package DeportManage;

//CustomerList class maintains the list of customers and perform actions like 
//Add customer, Search customer and remove customer by using their Parcel ID.

import java.util.ArrayList;

public class CustomerList {

//Maintains a list of Customer objects as an ArrayList
	private ArrayList<Customer> customerlist;
	
	/**
	 * Constructor of the class CustomerList
	 * Performs the initialisation for ArrayList of Customers
	 */
	public CustomerList ()
	{
		customerlist = new ArrayList<Customer> ();
	}
	
	/**
	 * Method to get customer list  
	 * @return Customer list as objects of customer in an ArrayList  
	 */    
	public ArrayList<Customer> getCustomerList()
	{
		return customerlist;
	}		
	
	/** 
	 * @return The size of Customer list
	 */
    public int getSize()
    {
    	return customerlist.size();
    }
	/**
	 * Method to add customers in the Customer list 
	 * @param customer, the object customer of type Customer
	 * Check if the parcel ID is in the Customer List
	 * @throws DuplicateException 
	 */
	public void addCustomer(Customer customer) throws DuplicateException
	{
		String id = customer.getParcelID();
		if (isExistParcelID(id) == true)
			throw new DuplicateException(id);
		else
			customerlist.add(customer);
	}
	/**
	 * Method to ensure whether there is customer with the same parcel ID
	 * @return boolean true or false
	 */
	private boolean isExistParcelID(String id)
	{
		for (Customer c : customerlist)
		{
			if (c.getParcelID().equals(id))
			{
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Method to ensure whether there is seqence number
	 * @return boolean true or false
	 */
	public boolean isExistSeqNo(int seq_No)
	{
		for (Customer c : customerlist)
		{
			if (seq_No == c.getSequenceNo())
			{
				return true;
			}
		}
		return false;
	}
	/**
	 * Method to search customer by their parcel ID  
	 * @param id, the parcel ID of type String
	 * @return the customer found in customer list
	 * @throws NotFoundCustomerByNoException
	 */
	public Customer searchCustomerBySequenceNo(int sequence_no) throws NotFoundCustomerByNoException
	{
		for (Customer c : customerlist)
		{
			if (c.getSequenceNo() == sequence_no)
			{
				return c;
			}
		}
		 throw new NotFoundCustomerByNoException(sequence_no);
	}
	/**
	 * Method to remove customer by their parcel ID  
	 * @param id, the parcel ID of type String
	 */
	public void removeCustomer(Customer cm)
	{
		customerlist.remove(cm);
	}
}

